<?php 
namespace backend\controllers;


use Yii;
use yii\db\Query;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use backend\controllers\CommonController;
class RbacController extends CommonController{
	public function actionIndex(){
		$auth = Yii::$app->authManager;
		$role=$auth->createRole(null);
		var_dump($role);
	}

	public function actionCreaterole() {
		return $this->render('_createitem');
	}

	//角色列表
    public function actionRoles(){
        $auth = Yii::$app->authManager;
        $data = new ActiveDataProvider([
            'query' => (new Query)->from($auth->itemTable)->where('type = 1')->orderBy('created_at desc'),
            'pagination' => ['pageSize' => 5], //  分页数设置
        ]);
        return $this->render('_items', ['dataProvider' => $data]);
    }

    //创建规则
    public function actionCreaterule()
    {
        // if (Yii::$app->request->isPost) {
        //     $post = Yii::$app->request->post();
        //     if (empty($post['class_name'])) {
        //         throw new \Exception('参数错误');
        //     }
        //     $className = "app\\models\\". $post['class_name'];
        //     if (!class_exists($className)) {
        //         throw new \Exception('规则类不存在');
        //     }
        //     $rule = new $className;
        //     if (Yii::$app->authManager->add($rule)) {
        //         Yii::$app->session->setFlash('info', '添加成功');
        //     }
        // }
        return $this->render("_createrule");
    }

}